﻿
function generateYears(startYear, step) {
    return optionEnumerator(startYear, startYear + step, null);
}
function generateMonths() {
    var count = 12;
    return optionEnumerator(1, count + 1, null);
}
var bigMonth = ["1", "3", "5", "7", "8", "10", "12"];
var smallMonth = ["4", "6", "9", "11"];
function generateDays(year, month) {
    var isSpeciYear = false;
    var count = 31;
    if ($.inArray(month, smallMonth) > -1) {
        count = 30;
    } 
    if (month == 2) {
        isSpeciYear = isRYear(year);
        count = isSpeciYear ? 28 : 29;
    }

    return optionEnumerator(1, count + 1, null);
}
function isRYear(year) {
    return ((year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0));
}

function generateYeasFrom(start,end,sort)
{
	 
		  return optionEnumeratorBySort(start,end,null,sort);
		  
	 
	 
}

function validateDateTime(dateTime1,dateTime2)
{
	var   d1   = new  Date(dateTime1.replace(/\-/g, "\/"));
	var   d2   = new  Date(dateTime2.replace(/\-/g, "\/"));        
	//alert(d1+","+d2);
	if(d1>d2)
	{
	    alert("结束时间必须在开始时间之后!");
	    return false;
	}
	
	d2 = new Date(getCurrentDateTime("-",true).replace(/\-/g, "\/"));
	//alert(d1+","+d2);
	if(d1<d2)
	{
		alert("起始时间必须大于当前时间!");
	    return false;
	}
	
	return true;  
	
}



function getCurrentDateTime(spl,needTime){
		  var now= new Date();  
		var year=now.getYear();  
		var month=now.getMonth()+1;  
		var day=now.getDate();
		var result = "";
				if(month<10)
	{
	result= year+spl+"0"+month+spl+day;
	}
	else { result = year+spl+month+spl+day;}
				if(needTime)
				{
					result = result + " " + now.getHours()+":" +now.getMinutes()+":"+now.getSeconds();
				}else
	result = result ;
	
	return result;
	
			
}


function loadTime() {

       var optionBuilder = function (temp) {
           return '<option value="' + temp + '">' + temp + "</option>";
       };

       var times = "";
       for (var i = 0; i < 24; i++) {
           times += (optionBuilder(i + ":00") + optionBuilder(i + ":30"));
       } 
       return times;
   }



function optionEnumeratorBySort(start, end, templete,sort) {
    var result = '<option value="-1">&nbsp;&nbsp;</option>';
    if (templete == null || templete == "") {
        templete = function (i) {
            return ('<option value="' + i + '">' + i + '</option>');
        };
    }
    
    if(sort=='ASC')
    for (var i = start; i < end; i++) {
        result += templete(i);
    }
    else if(sort=='DESC')
    {
    	 for (var i = end; i >= start; i--) {
    	        result += templete(i);
    	    } 
    }
    return result;
}
var montharr = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
 function returnMonth (num){
  
    return montharr[num];
}

function optionEnumerator(start,end,templete)
{
	return optionEnumeratorBySort(start,end,templete,"ASC");
}